/*
 * @Author: 搁浅小时光 mork_wu@163.com
 * @Date: 2022-06-30 13:36:59
 * @LastEditors: 搁浅小时光 mork_wu@163.com
 * @LastEditTime: 2022-06-30 13:46:21
 * @FilePath: \limsVite\src\utils\request.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios from "axios";
import { ElMessage } from "element-plus";

const instance = axios.create({
    baseURL: 'https://api.lims2.com/api',
    withCredentials: true,
    timeout: 5000
  })
  instance.interceptors.request.use(
    config => {
      return config
    },
    error => {
      console.log(error)
      return Promise.reject(error)
    }
  )
  instance.interceptors.response.use(
    response => {
      const res = response.data
      if (res.status !== 200) {
        ElMessage({
          message: res.message || 'Error',
          type: 'error',
          duration: 5 * 1000
        })
        return Promise.reject(new Error(res.message || 'Error'))
      } else {
        return res.data
      }
    },
    error => {
      console.log('err' + error) // for debug
      ElMessage({
        message: error.message,
        type: 'error',
        duration: 5 * 1000
      })
      return Promise.reject(error)
    }
  )